<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>正则表达式</title>
</head>

<body>
  <script>
    /* 
      replace()
      match()
      search()
      test()
    */

    // replace()
    var str = 's]2[ab]3[cd45s[4d]]]'
    console.log('%c原字符串' + str, 'color:green')
    var str1 = str.replace(/(\d+)\[/g, function (str, $1, index) {
      console.log('replace查找到的符合项：' + str + '被替换的字符是' + $1)
      return '='
    })
    console.log('replace()', str1)

    // search()
    var str2 = str.search(/(\d+)\w/g)
    console.log('search()', str2)

    // match()
    var str3 = str.match(/^(\w+)\]/)
    console.log('match()',str3)

    // test()
    var str4 = /(\d+)/.test(str)
    console.log('test()',str4)

    // 其他

    // string
    console.log('%c=======---string 相关---======','color:#03ccbb')
    var s = '0123456789'
    console.log('原字符串',s)
    console.log('substr()',s.substr(2,4))
    console.log('原字符串',s)
    console.log('substring',s.substring(2,4))
    console.log('原字符串',s)
  </script>
</body>

</html>